package com.lc.oss.config;

import com.aliyun.oss.OSSClient;
import com.lc.oss.properties.AliYunOssProperties;
import com.lc.oss.properties.QiNiuOssProperties;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @description: some desc
 * @author: LChuang
 * @date: 2023/11/30 17:04
 */
@Configuration
public class OssConfig {

    @Resource
    private QiNiuOssProperties qiNiuOssProperties;

    @Resource
    private AliYunOssProperties aliYunOssProperties;

    /**
     * qiNiu选择空间的存储区域，生成上传管理器
     */
    @Bean
    public UploadManager UploadManager() {
        com.qiniu.storage.Configuration configuration = null;
        switch (qiNiuOssProperties.getZone()) {
            case "huadong":
                configuration = new com.qiniu.storage.Configuration(Region.huadong());
                return new UploadManager(configuration);
            case "huabei":
                configuration = new com.qiniu.storage.Configuration(Region.huabei());
                return new UploadManager(configuration);
            case "huanan":
                configuration = new com.qiniu.storage.Configuration(Region.huanan());
                return new UploadManager(configuration);
            case "beimei":
                configuration = new com.qiniu.storage.Configuration(Region.beimei());
                return new UploadManager(configuration);
            default:
                throw new RuntimeException("七牛云存储区域配置错误");
        }
    }

    @Bean
    public OSSClient getOSSClient(){
        return new OSSClient(aliYunOssProperties.getEndpoint(), aliYunOssProperties.getAccessKey(), aliYunOssProperties.getSecretKey());
    }

}
